<template>
  <div class="country-region-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <div class="operation-btn-wrapper">
        <a-button type="primary" @click="addHandle">新增</a-button>
      </div>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
      >
        <template #status="{ row }">
          <a-tag v-if="row.status === 1" color="#87d068"> 启用 </a-tag>
          <a-tag v-if="row.status === 0" color="#cd201f"> 停用 </a-tag>
        </template>
        <template #action="{ row }">
          <a-button type="link" :danger="row.status === 1" @click="changeStatusHandle(row)">{{ row.status === 0 ? "启用" : "停用" }}</a-button>
          <a-button type="link" @click="editHandle(row)">编辑</a-button>
        </template>
      </super-table>
    </div>
    <a-modal v-model:visible="dialogOpts.visible" :maskClosable="false" :keyboard="false" :closable="false" :footer="null" :title="dialogOpts.title" :width="dialogOpts.width">
      <component v-model:visible="dialogOpts.visible" :is="dialogOpts.component" :type="dialogOpts.type" :pass-data="dialogOpts.passData" @submit="dialogSubmitHandle"></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import AddRegion from "./components/addRegion/index.vue";
export default {
  name: "CountryRegion",
  components: {
    AddRegion
  }
};
</script>
<script lang="ts" setup>
import TableHeightHook from "@/hook/tableHeightHook";
import ModalHook from "@/hook/modalHook";
import { searchItemList, tableColumn } from "./data";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
const { tableHeight, loading } = TableHeightHook(50);
const { searchForm, tableData, dialogOpts } = InitHook();
const { searchHandle, getData, changeStatusHandle, editHandle, addHandle } = OperationHook({ searchForm, tableData, loading, dialogOpts });
const { dialogSubmitHandle } = ModalHook({
  dialogOpts,
  callBack: getData
});
getData();
</script>
<style lang="stylus" scoped></style>
